
#include "aero_menu.h"
#include "oled_spi_sh1106.h"
#include <stddef.h>
#include <stdlib.h>

//extern Menu *currentMenu;//当前的菜单

/*
  高亮显示第几行
  行号，
  起点
  字符串
  模式
*/
void aeroDisplayLine(unsigned char line,Menu *currentMenu)
{
  int i;
  line = 3-(currentMenu->range_to-line);
  oled_fill(0,0,127,63,0);

  for(i=0;i<4;i++){
    if ( line == i)
      oled_showstring(2,16*i,currentMenu->menuItems[i+currentMenu->range_from],0);
    else  
      oled_showstring(2,16*i,currentMenu->menuItems[i+currentMenu->range_from],1);
    }
  oled_refresh_gram();  
}

// 用于显示菜单项
// void display(u8 line) //显示菜单项并设置选中的项反白
// {
//  int i;
//  line = 3-(currentMenu->range_to-line);
//  Lcd_Fill(0x00);
//  for(i = 0;i<4;i++)
//  {
//   Lcd_Disp(i+1,0,currentMenu->menuItems[i+currentMenu->range_from]);
//  }
//  highlight(0,line,8,255);//反白显示指定行
// }
// void func(void)
// {

// printf("hello");
// }

/*

int main(void)
 {
 
  delay_init();
  uart_init(9600);
  Lcd_Init();
  KEY_Init();
  initMenu();
  display(currentMenu->selected);
  while(1)
 {
  key = KEY_Scan();
  if(key == 0)
  {
   delay_ms(10);
   continue;
  }
  printf("key %d is press",key);
  switch(key)
  {
   case 12://向上
    if(currentMenu->selected == 0)//到了第一项
     break;
    else
    {
     currentMenu->selected--;
     if(currentMenu->selected < currentMenu->range_from)//更新显示的区域
     {
      currentMenu->range_from = currentMenu->selected;
      currentMenu->range_to = currentMenu->range_from+3;
     }
     display(currentMenu->selected);
     break;
    }
   case 8://向下
    if(currentMenu->selected == currentMenu->itemCount-1)
     break;
    else
    {
     currentMenu->selected++;
     if(currentMenu->selected>currentMenu->range_to)
     {
      currentMenu->range_to = currentMenu->selected;
      currentMenu->range_from = currentMenu->range_to-3;
     }
     display(currentMenu->selected);
     break;
    }
   case 4://Enter键
   {
    if(currentMenu->subMenus[currentMenu->selected] !=NULL)
    {
     currentMenu = currentMenu->subMenus[currentMenu->selected];
     display(0);
    }
    else
    {
     if(currentMenu->func[currentMenu->selected] != NULL)
     {
      currentMenu->func[currentMenu->selected]();//执行相应的函数
      display(currentMenu->selected);//返回后恢复原来的菜单状态
     }
    }
    break;
   }
   case 3://返回键
   {
    if(currentMenu->parent!=NULL)//父菜单不为空，将显示父菜单
    {
     currentMenu = currentMenu->parent;
     display(currentMenu->selected);
    }
    break;
   }
   default:
     break;
  }
  delay_ms(10);
 }
}

*/